
<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form" action="" lay-filter="search-form">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">项目</label>
                            <div class="layui-input-inline">
                                <select name="projectId" lay-filter="projectId">
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">主机</label>
                            <div class="layui-input-inline">
                                <select name="hostId" lay-filter="hostId">
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">任务名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="jobName" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">任务组名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="jobGroup" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn" lay-submit lay-filter="data-search-btn">
                                <i class="layui-icon layui-icon-search"></i>搜 索
                            </button>
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit
                                    lay-filter="data-reset-btn">
                                <i class="layui-icon layui-icon-refresh"></i> 重 置
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>
        <div class="layuimini-table">
            <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        </div>
    </div>
</div>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm data-add-btn" lay-event="add">新增</button>
    </div>
</script>

<script type="text/html" id="currentTableBar">
    <a class="layui-btn layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="executeonce">执行一次</a>
    <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
</script>

<script type="text/html" id="switchTpl">
    <input type="checkbox" name="quartzStatus" value="{{= d.id }}" lay-skin="switch" lay-text="启动|停止"
           lay-filter="jobStatusDemo" {{= d.status== 0 ? "checked" : "" }}>
</script>

<script type="text/html" id="jobTriggerTpl">
    {{#  if(d.jobTrigger == 'CRON'){ }}
    <span class="layui-badge layui-bg-blue">CRON</span>
    {{#  } else { }}
    <span class="layui-badge layui-bg-blue">固定速度</span>
    {{#  } }}
</script>

<script type="text/html" id="addDialog">
    <div class="layuimini-form">
        <form class="layui-form" action="" lay-filter="add-form" id="add-form">

            <div class="layui-row">
                <div class="layui-col-md6">
                    <div class="layui-form-item label-wide">
                        <label class="layui-form-label required">项目</label>
                        <div class="layui-input-block">
                            <select name="projectId" lay-filter="projectId" lay-verify="required">
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item label-wide">
                        <label class="layui-form-label required">任务名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="jobName" lay-verify="required" lay-reqtext="任务名称不能为空" placeholder="请输入任务名称" value="" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item label-wide">
                        <label class="layui-form-label required">触发器类型</label>
                        <div class="layui-input-block">
                            <input type="radio" name="jobTrigger" lay-filter="jobTrigger" value="SIMPLE" title="固定速度" checked>
                            <input type="radio" name="jobTrigger" lay-filter="jobTrigger" value="CRON" title="CRON" >
                        </div>
                    </div>
                    <div class="layui-form-item label-wide">
                        <label class="layui-form-label required">是否并发执行</label>
                        <div class="layui-input-block">
                            <input type="radio" name="concurrent" value="0" title="是">
                            <input type="radio" name="concurrent" value="1" title="否" checked>
                        </div>
                    </div>
                    <div class="layui-form-item label-wide">
                        <label class="layui-form-label required">请求方式</label>
                        <div class="layui-input-block">
                            <select name="jobType" lay-filter="jobType" lay-verify="required">
                                <option value="GET">GET</option>
                                <option value="POST">POST</option>
                                <option value="POST_JSON">POST_JSON</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item label-wide">
                        <label class="layui-form-label required">请求地址</label>
                        <div class="layui-input-block">
                            <input type="text" name="jobUrl" lay-verify="required" lay-reqtext="请求地址不能为空" placeholder="请输入请求地址" value="" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item label-wide">
                        <label class="layui-form-label required">主机</label>
                        <div class="layui-input-block">
                            <select name="hostId" lay-filter="hostId" lay-verify="required">
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item label-wide">
                        <label class="layui-form-label required">任务组</label>
                        <div class="layui-input-block">
                            <input type="text" name="jobGroup" lay-verify="required|groupCheck" lay-reqtext="任务组不能为空" placeholder="请输入任务组" value="" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item label-wide" id="intervalSecondsDiv">
                        <label class="layui-form-label required">固定速度</label>
                        <div class="layui-input-block">
                            <input type="number" name="intervalSeconds" placeholder="请输入（秒）执行一次" value="" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item label-wide layui-hide" id="cronExpressionDiv">
                        <label class="layui-form-label required">cron表达式</label>
                        <div class="layui-input-block">
                            <input type="text" name="cronExpression" placeholder="请输入cron表达式" value="" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item label-wide">
                        <label class="layui-form-label required">调度过期策略</label>
                        <div class="layui-input-block">
                            <select name="misfirePolicy" lay-filter="misfirePolicy" lay-verify="required">
                                <option value="1">立即执行</option>
                                <option value="2">执行一次</option>
                                <option value="3" selected>放弃执行</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item label-wide">
                        <label class="layui-form-label required">主机策略</label>
                        <div class="layui-input-block">
                            <select name="strategy" lay-filter="strategy" lay-verify="required">
                                <option value="ROUND" selected>轮询</option>
                                <option value="RANDOM">随机</option>
                                <option value="FIRST">第一个</option>
                                <option value="LAST">最后一个</option>
                                <option value="LFU">最不经常使用</option>
                                <option value="LRU">最近最久未使用</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-row">
                <div class="layui-col-md6">
                    <div class="layui-form-item label-wide">
                        <label class="layui-form-label">任务超时时间</label>
                        <div class="layui-input-block">
                            <input type="number" name="executorTimeout" placeholder="请输入任务超时时间" value="" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item label-wide">
                        <label class="layui-form-label">失败重试次数</label>
                        <div class="layui-input-block">
                            <input type="number" name="failRetryTimes" placeholder="请输入失败重试次数" value="" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item layui-form-text label-wide">
                <label class="layui-form-label">请求参数</label>
                <div class="layui-input-block">
                    <textarea name="jobParam" class="layui-textarea layui-textarea-small" placeholder="请输入请求参数信息(JSON格式)"></textarea>
                </div>
            </div>
            <div class="layui-form-item layui-form-text label-wide">
                <label class="layui-form-label">请求头</label>
                <div class="layui-input-block">
                    <textarea name="jobHeader" class="layui-textarea layui-textarea-small" placeholder="请输入请求头信息(JSON格式)"></textarea>
                </div>
            </div>
            <div class="layui-form-item layui-form-text label-wide">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <textarea name="remark" class="layui-textarea layui-textarea-small" placeholder="请输入备注信息"></textarea>
                </div>
            </div>
            <div class="layui-form-item text-right">
                <button class="layui-btn" lay-submit lay-filter="addSaveBtn">保存</button>
                <button class="layui-btn layui-btn-primary" type="button" lay-filter="closeAddDialog">取消</button>
            </div>
        </form>
    </div>
</script>


<script type="text/html" id="editDialog">
    <div class="layuimini-form">
        <form class="layui-form" action="" lay-filter="edit-form" id="edit-form">
            <div class="layui-row">
                <div class="layui-col-md6">
                    <div class="layui-form-item label-wide">
                        <label class="layui-form-label required">项目</label>
                        <div class="layui-input-block">
                            <select name="projectId" lay-filter="projectId" lay-verify="required">
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item label-wide">
                        <label class="layui-form-label required">任务名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="jobName" lay-verify="required" lay-reqtext="任务名称不能为空" placeholder="请输入任务名称" value="" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item label-wide">
                        <label class="layui-form-label required">触发器类型</label>
                        <div class="layui-input-block">
                            <input type="radio" name="jobTrigger" lay-filter="jobTrigger" value="SIMPLE" title="固定速度" checked>
                            <input type="radio" name="jobTrigger" lay-filter="jobTrigger" value="CRON" title="CRON" >
                        </div>
                    </div>
                    <div class="layui-form-item label-wide">
                        <label class="layui-form-label required">是否并发执行</label>
                        <div class="layui-input-block">
                            <input type="radio" name="concurrent" value="0" title="是">
                            <input type="radio" name="concurrent" value="1" title="否" checked>
                        </div>
                    </div>
                    <div class="layui-form-item label-wide">
                        <label class="layui-form-label required">请求方式</label>
                        <div class="layui-input-block">
                            <select name="jobType" lay-filter="jobType" lay-verify="required">
                                <option value="GET">GET</option>
                                <option value="POST">POST</option>
                                <option value="POST_JSON">POST_JSON</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item label-wide">
                        <label class="layui-form-label required">请求地址</label>
                        <div class="layui-input-block">
                            <input type="text" name="jobUrl" lay-verify="required" lay-reqtext="请求地址不能为空" placeholder="请输入请求地址" value="" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item label-wide">
                        <label class="layui-form-label required">主机</label>
                        <div class="layui-input-block">
                            <select name="hostId" lay-filter="hostId" lay-verify="required">
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item label-wide">
                        <label class="layui-form-label required">任务组</label>
                        <div class="layui-input-block">
                            <input type="text" name="jobGroup" lay-verify="required|groupCheck" lay-reqtext="任务组不能为空" placeholder="请输入任务组" value="" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item label-wide" id="intervalSecondsDiv">
                        <label class="layui-form-label required">固定速度</label>
                        <div class="layui-input-block">
                            <input type="number" name="intervalSeconds" placeholder="请输入（秒）执行一次" value="" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item label-wide layui-hide" id="cronExpressionDiv">
                        <label class="layui-form-label required">cron表达式</label>
                        <div class="layui-input-block">
                            <input type="text" name="cronExpression" placeholder="请输入cron表达式" value="" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item label-wide">
                        <label class="layui-form-label required">调度过期策略</label>
                        <div class="layui-input-block">
                            <select name="misfirePolicy" lay-filter="misfirePolicy" lay-verify="required">
                                <option value="1">立即执行</option>
                                <option value="2">执行一次</option>
                                <option value="3" selected>放弃执行</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item label-wide">
                        <label class="layui-form-label required">主机策略</label>
                        <div class="layui-input-block">
                            <select name="strategy" lay-filter="strategy" lay-verify="required">
                                <option value="ROUND" selected>轮询</option>
                                <option value="RANDOM">随机</option>
                                <option value="FIRST">第一个</option>
                                <option value="LAST">最后一个</option>
                                <option value="LFU">最不经常使用</option>
                                <option value="LRU">最近最久未使用</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-row">
                <div class="layui-col-md6">
                    <div class="layui-form-item label-wide">
                        <label class="layui-form-label">任务超时时间</label>
                        <div class="layui-input-block">
                            <input type="number" name="executorTimeout" placeholder="请输入任务超时时间" value="" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-form-item label-wide">
                        <label class="layui-form-label">失败重试次数</label>
                        <div class="layui-input-block">
                            <input type="number" name="failRetryTimes" placeholder="请输入失败重试次数" value="" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-form-text label-wide">
                <label class="layui-form-label">请求参数</label>
                <div class="layui-input-block">
                    <textarea name="jobParam" class="layui-textarea layui-textarea-small" placeholder="请输入请求参数信息(JSON格式)"></textarea>
                </div>
            </div>
            <div class="layui-form-item layui-form-text label-wide">
                <label class="layui-form-label">请求头</label>
                <div class="layui-input-block">
                    <textarea name="jobHeader" class="layui-textarea layui-textarea-small" placeholder="请输入请求头信息(JSON格式)"></textarea>
                </div>
            </div>
            <div class="layui-form-item layui-form-text label-wide">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <textarea name="remark" class="layui-textarea layui-textarea-small" placeholder="请输入备注信息"></textarea>
                </div>
            </div>
            <div class="layui-form-item text-right">
                <button class="layui-btn" lay-submit lay-filter="editSaveBtn">保存</button>
                <button class="layui-btn layui-btn-primary" type="button" lay-filter="closeEditDialog">取消</button>
            </div>
        </form>
    </div>
</script>

<script>
    layui.use(['form', 'table', 'miniAjax'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            miniAjax = layui.miniAjax;

        // 渲染项目下拉栏
        var projectList = [];
        miniAjax.get({
            url: '/project/select',
            success: function (res) {
                if (res.code == '0') {
                    projectList = res.data;
                    // 动态渲染项目下拉栏
                    $("[lay-filter='projectId']").append('<option value="">请选择</option>');
                    for (let item of projectList) {
                        $("[lay-filter='projectId']").append('<option value="' + item.id + '">' + item.projectName + '</option>');
                    }
                    form.render('select', 'search-form');
                } else {
                    layer.msg(res.msg, {time: 1000, icon: 2});
                }
            }
        });

        form.on('select(projectId)', function (data) {
            if (data.value) {
                miniAjax.get({
                    url: '/hosts/select?projectId=' + data.value,
                    success: function (res) {
                        if (res.code == '0') {
                            var hostList = res.data;
                            // 动态渲染项目下拉栏
                            $("[lay-filter='hostId']").empty();
                            $("[lay-filter='hostId']").append('<option value="">请选择</option>');
                            for (let item of hostList) {
                                $("[lay-filter='hostId']").append('<option value="' + item.id + '">' + item.hostName + '</option>');
                            }
                            form.render('select', 'search-form');
                        } else {
                            layer.msg(res.msg, {time: 1000, icon: 2});
                        }
                    }
                });
            } else {
                $("[lay-filter='hostId']").empty();
                form.render('select', 'search-form');
            }
        });

        var currTable = table.render({
            elem: '#currentTableId',
            url: '/jobinfo/query',
            method: 'post',
            contentType: 'application/json',
            request: {
                pageName: 'pageNo',
                limitName: 'pageSize'
            },
            parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.code,
                    "msg": res.msg,
                    "count": res.data.totalCount,
                    "data": res.data.records
                };
            },
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print'],
            cols: [[
                {field: 'id', width: 50, title: 'ID', align: 'center', fixed: 'left'},
                {field: 'jobName', width: 120, title: '任务名称'},
                {field: 'projectName', width: 120, title: '项目名称'},
                {field: 'hostName', width: 120, title: '主机名称'},
                {field: 'jobGroup', width: 120, title: '任务组'},
                {field: 'jobTrigger', width: 120, title: '触发器类型', templet: '#jobTriggerTpl'},
                {field: 'intervalSeconds', width: 120, title: '间隔时间(秒)'},
                {field: 'cronExpression', width: 120, title: 'cron表达式'},
                {field: 'jobType', width: 120, title: '请求方式'},
                {field: 'strategy', width: 120, title: '路由策略'},
                {field: 'status', width: 120, title: '任务状态', templet: '#switchTpl', align: 'center'},
                {field: 'createdBy', width: 80, title: '创建人'},
                {field: 'createdAt', width: 120, title: '创建时间'},
                {title: '操作', minWidth: 200, toolbar: '#currentTableBar', align: "center", fixed: 'right'}
            ]],
            autoSort: false,
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true,
            skin: 'line'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            // 执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                },
                where: data.field
            });
            return false;
        });

        // 监听重置操作
        form.on('submit(data-reset-btn)', function (data) {
            form.val("search-form", {
                "projectId": '',
                "hostId": '',
                "hostName": ''
            });
            // 执行搜索重载
            currTable.reload({
                page: {
                    curr: 1
                },
                where: form.val("search-form")
            });
            return false;
        });


        form.verify({
           groupCheck: function (value, item) {
               var pattern = /^[a-zA-Z0-9_]+$/;
               if (!pattern.test(value)) {
                 return '任务组只能由英文数字和下划线组成！';
               }
           }
        });


        // 监听启用/停用操作
        form.on('switch(jobStatusDemo)', function (obj) {
            console.log(this.value + ' ：' + this.name + '：' + obj.elem.checked);
            if (obj.elem.checked == true) {
                miniAjax.get({
                    url: '/jobinfo/start?id=' + this.value,
                    success: function (res) {
                        if (res.code == '0') {
                            layer.msg(res.msg, {time: 1000, icon: 1});
                        } else {
                            layer.msg(res.msg, {time: 1000, icon: 2});
                        }
                    }
                });
            } else {
                miniAjax.get({
                    url: '/jobinfo/stop?id=' + this.value,
                    success: function (res) {
                        if (res.code == '0') {
                            layer.msg(res.msg, {time: 1000, icon: 1});
                        } else {
                            layer.msg(res.msg, {time: 1000, icon: 2});
                        }
                    }
                });
            }
        });


        /**
         * toolbar事件监听
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') { // 监听添加操作
                var index = layer.open({
                    title: '新增任务',
                    type: 1,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: false,
                    area: '920px', // 宽度580, 高度自适应
                    content: $('#addDialog').html(),
                    success: function (layero, dIndex) {
                        // 渲染表单里的下拉框等
                        let selectHtml = '<option value="">请选择</option>';
                        for (let item of projectList) {
                            selectHtml += '<option value="' + item.id + '">' + item.projectName + '</option>';
                        }
                        layero.find("[name='projectId']").html(selectHtml);

                        form.render('select', 'add-form');
                        form.render('radio', 'add-form');

                        // 监听layer里面的下拉框，哦耶
                        form.on('select(projectId)', function (data) {
                            if (data.value) {
                                miniAjax.get({
                                    url: '/hosts/select?projectId=' + data.value,
                                    success: function (res) {
                                        if (res.code == '0') {
                                            var hostList = res.data;
                                            // 动态渲染项目下拉栏
                                            layero.find("[name='hostId']").empty();
                                            layero.find("[name='hostId']").append('<option value="">请选择</option>');
                                            for (let item of hostList) {
                                                layero.find("[name='hostId']").append('<option value="' + item.id + '">' + item.hostName + '</option>');
                                            }
                                            form.render('select', 'add-form');
                                        } else {
                                            layer.msg(res.msg, {time: 1000, icon: 2});
                                        }
                                    }
                                });
                            } else {
                                layero.find("[name='hostId']").empty();
                                form.render('select', 'add-form');
                            }
                        });

                        // 监听layer里面的单选框，哦耶
                        form.on('radio(jobTrigger)', function (data) {
                            var value = data.elem.value; // 获得 radio 值
                            if (value == "CRON") {
                                layero.find("#intervalSecondsDiv").addClass("layui-hide");
                                layero.find("#cronExpressionDiv").removeClass("layui-hide");
                            } else {
                                layero.find("#cronExpressionDiv").addClass("layui-hide");
                                layero.find("#intervalSecondsDiv").removeClass("layui-hide");
                            }
                        });

                        // 表单提交事件
                        form.on('submit(addSaveBtn)', function (data) {
                            console.log(JSON.stringify(data.field));

                            miniAjax.postJSON({
                                url: '/jobinfo/add',
                                data: JSON.stringify(data.field),
                                success: function (res) {
                                    if (res.code == '0') {
                                        layer.msg(res.msg, {
                                            time: 1000,
                                            icon: 1
                                        }, function () {
                                            layer.close(dIndex);
                                        });
                                    } else {
                                        layer.msg(res.msg, {time: 1000, icon: 2});
                                    }
                                }
                            });
                            return false;
                        });

                        // 监听取消按钮
                        $("button[lay-filter='closeAddDialog']").click(function () {
                            layer.close(dIndex);
                            return false;
                        });
                    },
                    end: function (index) {
                        // 重载表格，刷新数据
                        currTable.reload();
                    }
                });
            }
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var lineData = obj.data;
            if (obj.event === 'edit') {
                var index = layer.open({
                    title: '编辑任务',
                    type: 1,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: false,
                    area: '920px',
                    content: $('#editDialog').html(),
                    success: function (layero, dIndex) {
                        // 渲染表单里的下拉框等
                        let selectHtml = '';
                        for (let item of projectList) {
                            selectHtml += '<option value="' + item.id + '">' + item.projectName + '</option>';
                        }
                        layero.find("[name='projectId']").html(selectHtml);

                        form.render('select', 'edit-form');
                        form.render('radio', 'edit-form');

                        miniAjax.get({
                            url: '/hosts/select?projectId=' + lineData.projectId,
                            success: function (res) {
                                if (res.code == '0') {
                                    var hostList = res.data;
                                    // 动态渲染项目下拉栏
                                    layero.find("[name='hostId']").empty();
                                    layero.find("[name='hostId']").append('<option value="">请选择</option>');
                                    for (let item of hostList) {
                                        layero.find("[name='hostId']").append('<option value="' + item.id + '">' + item.hostName + '</option>');
                                    }
                                    form.render('select', 'edit-form');
                                    // 回显表单数据
                                    form.val('edit-form', lineData);
                                    // 回显特殊选项
                                    if (lineData.jobTrigger == 'CRON') {
                                        layero.find("#intervalSecondsDiv").addClass("layui-hide");
                                        layero.find("#cronExpressionDiv").removeClass("layui-hide");
                                    }
                                } else {
                                    layer.msg(res.msg, {time: 1000, icon: 2});
                                }
                            }
                        });


                        // 监听layer里面的下拉框（项目下拉框的变化）
                        form.on('select(projectId)', function (data) {
                            if (data.value) {
                                miniAjax.get({
                                    url: '/hosts/select?projectId=' + data.value,
                                    success: function (res) {
                                        if (res.code == '0') {
                                            var hostList = res.data;
                                            // 动态渲染项目下拉栏
                                            layero.find("[name='hostId']").empty();
                                            layero.find("[name='hostId']").append('<option value="">请选择</option>');
                                            for (let item of hostList) {
                                                layero.find("[name='hostId']").append('<option value="' + item.id + '">' + item.hostName + '</option>');
                                            }
                                            form.render('select', 'edit-form');
                                        } else {
                                            layer.msg(res.msg, {time: 1000, icon: 2});
                                        }
                                    }
                                });
                            } else {
                                layero.find("[name='hostId']").empty();
                                form.render('select', 'edit-form');
                            }
                        });


                        // 监听layer里面的单选框，哦耶
                        form.on('radio(jobTrigger)', function (data) {
                            var value = data.elem.value; // 获得 radio 值
                            if (value == "CRON") {
                                layero.find("#intervalSecondsDiv").addClass("layui-hide");
                                layero.find("#cronExpressionDiv").removeClass("layui-hide");
                            } else {
                                layero.find("#cronExpressionDiv").addClass("layui-hide");
                                layero.find("#intervalSecondsDiv").removeClass("layui-hide");
                            }
                        });

                        // 表单提交事件
                        form.on('submit(editSaveBtn)', function (data) {
                            data.field.id = lineData.id;
                            miniAjax.postJSON({
                                url: '/jobinfo/edit',
                                data: JSON.stringify(data.field),
                                success: function (res) {
                                    if (res.code == '0') {
                                        layer.msg(res.msg, {
                                            time: 1000,
                                            icon: 1
                                        }, function () {
                                            layer.close(dIndex);
                                        });
                                    } else {
                                        layer.msg(res.msg, {time: 1000, icon: 2});
                                    }
                                }
                            });
                            return false;
                        });

                        // 监听取消按钮
                        $("button[lay-filter='closeEditDialog']").click(function () {
                            layer.close(dIndex);
                            return false;
                        });
                    },
                    end: function (index) {
                        // 重载表格，刷新数据
                        currTable.reload();
                    }
                });
                return false;
            } else if (obj.event === 'delete') {
                layer.confirm('确定删除此任务吗', function (index) {
                    layer.close(index);
                    miniAjax.get({
                        url: '/jobinfo/delete?id=' + lineData.id,
                        success: function (res) {
                            if (res.code == '0') {
                                layer.msg(res.msg, {time: 1000, icon: 1});
                                // 重载表格，刷新数据
                                currTable.reload();
                            } else {
                                layer.msg(res.msg, {time: 1000, icon: 2});
                            }
                        }
                    });
                });
            } else if (obj.event === 'executeonce') {
                layer.confirm('确定执行一次该任务吗', function (index) {
                    layer.close(index);
                    miniAjax.get({
                        url: '/jobinfo/executeonce?id=' + lineData.id,
                        success: function (res) {
                            if (res.code == '0') {
                                layer.msg(res.msg, {time: 1000, icon: 1});
                            } else {
                                layer.msg(res.msg, {time: 1000, icon: 2});
                            }
                        }
                    });
                });
            }
        });

    });
</script>